﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Mt.Site.Web.Helpers;
using System.IO;
using System.Text;

namespace Mt.Site.Web.Startup
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CurrentDirectoryHelpers.SetCurrentDirectory();
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
            var config = new ConfigurationBuilder()
                .AddJsonFile("hosting.json", optional: true)   //增加hosting.json(用于独立发布时，配置访问端口等)
                .Build();


            return new WebHostBuilder()
                .UseKestrel(opt =>
                {
                    opt.AddServerHeader = false;
                    opt.Limits.MaxRequestLineSize = 16 * 1024;
                })
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIIS()
                .UseIISIntegration()
                .UseConfiguration(config)
                .UseStartup<Startup>();
        }
    }
}
